<template>
  <view class="coupon">
	  
	  <!-- 头部tab切换 -->
	  <view class="tab-bar">
	    <view 
	      v-for="(tab, index) in tabs" 
	      :key="index" 
	      class="tab-item"
	      :class="{ active: currentTab === index }"
	      @click="switchTab(index)"
	    >
	      {{ tab }}
	    </view>
	  </view>
    
    <!-- 优惠券列表 use_status` tinyint(1) DEFAULT 0 COMMENT '使用状态(0-未使用,1-已使用,2-已过期)', -->
	<view class="coupon-page">
		<view class="coupon-list">
		  <view 
		    v-for="(item, index) in couponList" 
		    :key="index" 
		    class="coupon-item"
		    :class="{'disabled': item.useStatus ==2 || item.useStatus ==1 ||item.expireDays==5 }"
		  >
		    <!-- 左侧金额区域 -->
		    <view class="coupon-left">
		      <view class="coupon-value">
		        <text class="currency">¥</text>
		        <text class="amount">{{item.amount}}</text>
		      </view>
		      <view class="coupon-condition" v-if="item.type==1">无门槛</view>
			  <view class="coupon-condition" v-if="item.type==2">满{{item.minSpend}}元可用</view>
		    </view>
		    
		    <!-- 右侧信息区域 -->
		    <view class="coupon-right">
		      <view class="coupon-name">{{item.name}}</view>
		      <view class="coupon-time">有效期至: {{item.expireTime}}</view>
		      <view class="coupon-status" >{{item.useStatus_dictText}}</view>
		    </view>
		  </view>
		</view>
	</view>
    
    
    <!-- 无优惠券提示 -->
    <view class="empty-tip" v-if="couponList.length === 0">
      <image src="/static/images/empty-coupon.png" mode="aspectFit"></image>
      <view>暂无可用优惠券</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      couponList: [],
	  page:1,
	  userInfo:'',
	  tabs: ['全部', '待使用', '已使用', '已过期',],
	  useStatus:'',
	  currentTab: 0,
    }
  },
  onLoad() {
	  this.userInfo= uni.getStorageSync("userInfo")
     this.getList()
  },
  methods: {
	switchTab(index) {
	    this.currentTab = index;
	    this.page = 1;
		if(index==0){
			this.useStatus=''
		}
		if(index==1){
			this.useStatus=0
		}
		if(index==2){
			this.useStatus=1
		}
		if(index==3){
			this.useStatus=2
		}
		this.getList()
	},
	getList(){
	 	 uni.showLoading({
	 	 	title: '加载中'
	 	 })
		 if(this.page==1){
			 this.couponList=[]
		 }
	 	 this.$http('jeecg-boot/app/market/bicCoupon/list',{
	 	 		   pageNo:this.page,
	 	 		   pageSize:10,
	 	 		   userId:this.userInfo.id,
				 // userId:'1958543121398665218',
				   useStatus:this.useStatus
	 	 },'GET').then(res => {
	 	 		   //console.log(res)
	 	 	 uni.hideLoading();
	 	 		 var List=res.result.records
	 	 		
	 	 		 this.couponList=[...this.couponList, ...List]
	 	 	 //this.goodsList2=res.result.records
	 	  })
	},
    getStatusClass(status) {
      return {
        'used': status === '已使用',
        'expired': status === '已过期',
        'unused': status === '未使用'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.coupon-page {
  padding: 30rpx;
  min-height: 100vh;
  background-color: #f7f7f7;
  
  .page-title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 30rpx;
    text-align: center;
  }
  
  .coupon-list {
    .coupon-item {
      display: flex;
      margin-bottom: 20rpx;
      height: 180rpx;
      border-radius: 12rpx;
      overflow: hidden;
      box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
      background: linear-gradient(to right, #ff5e5e, #ff8a5e);
      
      &.disabled {
        background: linear-gradient(to right, #cccccc, #aaaaaa);
        filter: grayscale(80%);
      }
      
      .coupon-left {
        width: 220rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        color: #fff;
        
        .coupon-value {
          display: flex;
          align-items: flex-start;
          
          .currency {
            font-size: 32rpx;
            margin-right: 6rpx;
          }
          
          .amount {
            font-size: 60rpx;
            font-weight: bold;
            line-height: 1;
          }
        }
        
        .coupon-condition {
          font-size: 24rpx;
          margin-top: 10rpx;
        }
      }
      
      .coupon-right {
        flex: 1;
        padding: 20rpx;
        background-color: #fff;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        
        .coupon-name {
          font-size: 28rpx;
          color: #333;
          font-weight: bold;
        }
        
        .coupon-time {
          font-size: 24rpx;
          color: #999;
        }
        
        .coupon-status {
          align-self: flex-end;
          font-size: 24rpx;
          padding: 4rpx 12rpx;
          border-radius: 20rpx;
          
          &.unused {
            color: #ff5e5e;
            background-color: #ffeeee;
          }
          
          &.used {
            color: #999;
            background-color: #f5f5f5;
          }
          
          &.expired {
            color: #999;
            background-color: #f5f5f5;
          }
        }
      }
    }
  }
  
  .empty-tip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 100rpx;
    
    image {
      width: 300rpx;
      height: 300rpx;
      margin-bottom: 30rpx;
    }
    
    view {
      font-size: 28rpx;
      color: #999;
    }
  }
}
/* 头部tab栏 */
.tab-bar {
  display: flex;
  height: 90rpx;
  background-color: #fff;
  border-bottom: 1rpx solid #eee;
  position: sticky;
  top: 0;
  z-index: 10;
}

.tab-item {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 28rpx;
  color: #666;
  position: relative;
  padding: 24rpx 0;
}

.tab-item.active {
  color: #FF2442;
  font-weight: bold;
}

.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60rpx;
  height: 4rpx;
  background-color: #FF2442;
  border-radius: 2rpx;
}
</style>